//封装一个函数：获取登录时间
export const getTime = () => {
    let message = ''
    //通过内置构造函数Date
    const hours = new Date().getHours()
    if (hours >= 6 && hours <= 9) {
        message = '早上'
    } else if (hours <= 12) {
        message = '上午'
    } else if (hours <= 18) {
        message = '下午'
    } else {
        message = '晚上'
    }
    return message
}

import dayjs from 'dayjs'
// 格式化聊天页面时间显示
export const chatTime = (time: any) => {
    const now = dayjs()

    if (now.isSame(time, 'day')) {
        return `${time.format('HH:mm')}`
    } else if (now.subtract(1, 'day').isSame(time, 'day')) {
        return `昨天 ${time.format('HH:mm')}`
    } else if (now.isSame(time, 'year')) {
        return time.format('MM月DD日 HH:mm')
    } else {
        return time.format('YYYY年MM月DD日 HH:mm')
    }
}

// 格式化好友列表时间显示
export const friendTime = (time: any) => {
    if (!time) {
        return ''
    }

    const now = dayjs()

    if (now.isSame(time, 'day')) {
        return `${time.format('HH:mm')}`
    } else if (now.subtract(1, 'day').isSame(time, 'day')) {
        return `昨天`
    } else if (now.isSame(time, 'year')) {
        return time.format('MM月DD日')
    } else {
        return time.format('YYYY年MM月DD日')
    }
}
